<!doctype html>
<html>

<head>
    <meta content="text/html; charset=UTF-8" http-equiv="Content-Type" />
    <title>图片上传预览</title>
</head>

<body onload="loadImageFile();">
    <form name="uploadForm">
        <table>
            <tbody>
                <tr>
                    <td><img id="uploadPreview" style="width: 100px; height: 100px;" src="data:image/svg+xml,%3C%3Fxml%20version%3D%221.0%22%3F%3E%0A%3Csvg%20width%3D%22153%22%20height%3D%22153%22%20xmlns%3D%22http%3A//www.w3.org/2000/svg%22%3E%0A%20%3Cg%3E%0A%20%20%3Ctitle%3ENo%20image%3C/title%3E%0A%20%20%3Crect%20id%3D%22externRect%22%20height%3D%22150%22%20width%3D%22150%22%20y%3D%221.5%22%20x%3D%221.500024%22%20stroke-width%3D%223%22%20stroke%3D%22%23666666%22%20fill%3D%22%23e1e1e1%22/%3E%0A%20%20%3Ctext%20transform%3D%22matrix%286.66667%2C%200%2C%200%2C%206.66667%2C%20-960.5%2C%20-1099.33%29%22%20xml%3Aspace%3D%22preserve%22%20text-anchor%3D%22middle%22%20font-family%3D%22Fantasy%22%20font-size%3D%2214%22%20id%3D%22questionMark%22%20y%3D%22181.249569%22%20x%3D%22155.549819%22%20stroke-width%3D%220%22%20stroke%3D%22%23666666%22%20fill%3D%22%23000000%22%3E%3F%3C/text%3E%0A%20%3C/g%3E%0A%3C/svg%3E"
                            alt="Image preview" /></td>
                    <td><input id="uploadImage" type="file" name="myPhoto" onchange="loadImageFile();" /></td>
                </tr>
            </tbody>
        </table>
        <p><input type="submit" value="上传" /></p>
    </form>
    <script type="text/javascript">
        var oFReader = new FileReader(),
            rFilter =
            /^(?:image\/bmp|image\/cis\-cod|image\/gif|image\/ief|image\/jpeg|image\/jpeg|image\/jpeg|image\/pipeg|image\/png|image\/svg\+xml|image\/tiff|image\/x\-cmu\-raster|image\/x\-cmx|image\/x\-icon|image\/x\-portable\-anymap|image\/x\-portable\-bitmap|image\/x\-portable\-graymap|image\/x\-portable\-pixmap|image\/x\-rgb|image\/x\-xbitmap|image\/x\-xpixmap|image\/x\-xwindowdump)$/i;

        oFReader.onload = function (oFREvent) {
            document.getElementById("uploadPreview").src = oFREvent.target.result;
        };

        function loadImageFile() {
            if (document.getElementById("uploadImage").files.length === 0) {
                return;
            }
            var oFile = document.getElementById("uploadImage").files[0];
            if (!rFilter.test(oFile.type)) {
                alert("You must select a valid image file!");
                return;
            }
            oFReader.readAsDataURL(oFile);
        }
    </script>
    <input type="" id="clock" name="" value="">
    <input type="" id="clock1" name="" value="">
</body>

<script type="text/javascript">
    //设置cookie(超期时间，单位分钟)
    function setcookie(name, value, expiredays) {
        var exdate = new Date();
        exdate.setTime(exdate.getTime() + expiredays * 1000 * 60);
        document.cookie = name + "=" + escape(value) + ((expiredays == null) ? "" : ";expires=" + exdate.toGMTString())
    }
    //获取cookie
    function getcookie(name) {
        var arr = document.cookie.match(new RegExp("(^| )" + name + "=([^;]*)(;|$)"));
        if (arr != null) {
            return unescape(arr[2]);
        }
        return "";
    }
    //删除cookie(设置一个超期时间为过去的时间)
    function delcookie(name) {
        setcookie(name, "", -1);
    }

    //获取当前时间 "2017-09-27 17:53:26"
    function getNowFormatDate() {
        var date = new Date();
        var seperator1 = "-";
        var seperator2 = ":";
        var month = date.getMonth() + 1;
        var strDate = date.getDate();
        if (month >= 1 && month <= 9) {
            month = "0" + month;
        }
        if (strDate >= 0 && strDate <= 9) {
            strDate = "0" + strDate;
        }
        var currentdate = date.getFullYear() + seperator1 + month + seperator1 + strDate +
            " " + date.getHours() + seperator2 + date.getMinutes() +
            seperator2 + date.getSeconds();
        return currentdate;
    }

    // 获取当前时间 "2017-09-27 17:53:26"
    // <input type="" id="clock" name="" value="">
    function getNowDate() {
        var date = new Date();
        var seperator1 = "-";
        var seperator2 = ":";
        var month = date.getMonth() + 1;
        var strDate = date.getDate();
        if (month >= 1 && month <= 9) {
            month = "0" + month;
        }
        if (strDate >= 0 && strDate <= 9) {
            strDate = "0" + strDate;
        }

        var h = date.getHours();
        if (h >= 0 && h < 10) {
            h = "0" + h;
        }
        var m = date.getMinutes();
        if (m >= 0 && m <= 9) {
            m = "0" + m;
        }
        var s = date.getSeconds();
        if (s >= 0 && s <= 9) {
            s = "0" + s;
        }

        return date.getFullYear() + seperator1 + month + seperator1 + strDate + " " + h + seperator2 + m + seperator2 +
            s;
    }

    function clock() {
        var t = getNowDate()
        document.getElementById("clock").value = t
    }
    var int = setInterval("clock()", 1000)

   

    function getNowHiDate() {
        var date = new Date();
        var i = date.getMinutes();
        if (i >= 0 && i <= 9) {
            i = "0" + i;
        }
        var h = date.getHours();
        if (h >= 0 && h < 10) {
            h = "0" + h;
        }
        return h + ":" + i;
    }

    function checkhi(str) {
        if (str == null || str == "") {
            return false;
        }
        return new RegExp(/^([01]\d|2[0-3]):([0-5]\d)$/).test(str);
    }
</script>

</html>